/**
 * 功能描述 表单
 */

define(function (require, exports, module){
	var Form = require("form");
	var aw = require("ajaxwrapper");
	var store =require("store");
	var activeUser = store.get("user");
	
	var instance = {
		initComponent: function (params,widget){
            var form=new Form({
				parentNode:".J-form",
				show:false,
				saveaction:function(){
        			var data = form.getData();
					aw.saveOrUpdate("api/restaurant/dishprice/save",data,function(data){
						widget.get("grid").refresh();
						widget.show([".J-grid"]).hide([".J-form"]);
						widget.get("subnav").show(["add","search"]);//.hide(["return"])
					});
        			
        		},
        		cancelaction : function(){
           			     widget.show([".J-grid"]).hide([".J-form"]);
    					 widget.get("subnav").show(["add","search"]);//.hide(["return"])
    					 widget.get("grid").refresh();
        		},
				model:{
					id:"form",
					layout: "2_1",
					items:[{
						name:"pkDishPrice",
						type:"hidden",
					},{
						name:"version",
						defaultValue:"0",
						type:"hidden"
					},{
						name:"priceType",
						label:"定价类型",
						type:"select",
						validate:["required"],
						options:[{
							key:"Dish",
							value:"菜品"
						},{
							key:"SetMeal",
							value:"套餐"
						}]
					},{
						name:"dish",
						label:"菜品名称",
						url:"api/cater/dish/query",
						key:"pkDish",
						value:"name",
						type:"select",
						validate:["required"]
					},{
						name:"price",
						label:"单价(元/份)",
						validate:["required"]
					}]
				}
			});
			widget.set("form", form);
		}
	};
	module.exports = instance;
});